﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ZG_member.BLL;
using System.Configuration;
using System.IO;
using System.Security.Cryptography;
using VisualCardPrinter_NPPrinter;
using System.Text.RegularExpressions;
using ZG_member;


namespace ZG_member
{
    public partial class publishCardForm : Form
    {
        MainForm mainForm;
        string id = "0";
        string memberId = "0";
        //自动生成时
        string strMenberID = "";

        public publishCardForm(MainForm m, string ids, VisualCardPrinter_NPPrinter_New.VisualCardPrinter_NPPrinter ps)
        {
            InitializeComponent();
            mainForm = m;
            this.Opacity = 0;
            ZG_member.BLL.memberInfo meminfos = new ZG_member.BLL.memberInfo();
            skinEngine1.SkinFile = Application.StartupPath + ConfigurationManager.AppSettings["Skin"];
            if (ids != null)
            {
                id = ids;
                this.mb = meminfos.GetModeCard(id);
            }

            vnp = ps;
        }
        public publishCardForm(MainForm m, VisualCardPrinter_NPPrinter_New.VisualCardPrinter_NPPrinter ps, string memberid)
        {
            InitializeComponent();
            mainForm = m;
            this.Opacity = 0;
            ZG_member.BLL.memberInfo meminfos = new ZG_member.BLL.memberInfo();
            skinEngine1.SkinFile = Application.StartupPath + ConfigurationManager.AppSettings["Skin"];
            if (memberid != null)
            {
                memberId = memberid;
                this.mb = meminfos.GetModels(memberid);
            }

            vnp = ps;
        }
        public static string userName;
        public bool shoushu = false;
        ZG_member.Model.memberInfo mb;
        public static int UpdateId;
        VisualCardPrinter_NPPrinter_New.VisualCardPrinter_NPPrinter vnp;
        public static ZG_member.Model.memberInfo meminfomodel;
        bool PortAddUser = true;
        string Write = "";
        string picName = "员工.png";
        bool updatePic = false;
         public static string GetNumber(string str)
        {
            string result = "0";
            if (str != null && str != string.Empty)
            {

                // 正则表达式剔除非数字字符（不包含小数点.）
                str = Regex.Replace(str, @"[^\d.\d]", "");
                // 如果是数字，则转换为decimal类型
                if (Regex.IsMatch(str, @"^[+-]?\d*[.]?\d*$"))
                {
                    result = str.ToString();
                }
            }
            return result;
        }

        public int getStringLength(string str)
        {
            if (str.Equals(string.Empty))
                return 0;
            int strlen = 0;
            ASCIIEncoding strData = new ASCIIEncoding();
            //将字符串转换为ASCII编码的字节数字
            byte[] strBytes = strData.GetBytes(str);
            for (int i = 0; i <= strBytes.Length - 1; i++)
            {
                if (strBytes[i] == 63)  //中文都将编码为ASCII编码63,即"?"号
                    strlen++;
                strlen++;
            }
            return strlen;
        }
        public void Areas()
        {
            ZG_member.BLL.Areas area = new ZG_member.BLL.Areas();
            DataSet ds = area.GetList("");
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                cbxArea.Items.Add(ds.Tables[0].Rows[i]["AreaName"]);
            }

        }

        public void tianjiayanzheng()
        {
            ZG_member.BLL.memberInfo member = new ZG_member.BLL.memberInfo();
            ZG_member.Model.memberInfo memberMode = new ZG_member.Model.memberInfo();

            strMenberID = this.txtMenberId.Text;
            memberMode = member.GetModels(strMenberID);
            if (memberMode != null)
            {
                int menberID = Convert.ToInt32(this.txtMenberId.Text);
                menberID = menberID + 1;

                strMenberID = menberID.ToString().Replace('4', '5').PadLeft(6, '0');
                this.txtMenberId.Text = strMenberID;
                tianjiayanzheng();

            }
            else
            {
                this.txtMenberId.Text = strMenberID;
            }
        }



        public void Load_CBXWorker()
        {
            BLL.SalesStaffList sale = new BLL.SalesStaffList();
            this.txtOpenTeacher.DataSource = sale.GetListWhere("").Tables[0];
            this.txtOpenTeacher.DisplayMember = "SalesPersonId";
            this.txtOpenTeacher.ValueMember = "Id";


        }




        private void publishCardForm_Load(object sender, EventArgs e)
        {
            

            this.lbNameFK.ForeColor = Color.Red;
            this.lbGenderFK.ForeColor = Color.Red;
            this.lbTelFK.ForeColor = Color.Red;
            this.lbPassFK.ForeColor = Color.Red;
            this.lbPassFK2.ForeColor = Color.Red;
            this.lbChushengFK.ForeColor = Color.Red;
            this.lbAreaFK.ForeColor = Color.Red;
            this.lbOpenTeacherFK.ForeColor = Color.Red;
            Load_CBXWorker();
            Areas();
            this.timer1.Start();
            ZG_member.BLL.consumeSolution cm = new ZG_member.BLL.consumeSolution();
            ZG_member.BLL.Areas area = new ZG_member.BLL.Areas();
            ZG_member.Model.Areas areaMode = new ZG_member.Model.Areas();
            this.cmbType.DataSource = cm.GetModelList("");
            this.cmbType.DisplayMember = "solutionName";
            this.cmbType.ValueMember = "id";
            this.cbxsex.Text = "男";
            this.cbxStatus.Text = "正常";
            this.dateExpiresDate.Value = DateTime.Now.AddYears(1);
            if (this.Text!="添加会员"&&this.Text!="添加用户")
            {
            
                ZG_member.BLL.roleInfo role = new ZG_member.BLL.roleInfo();
                ZG_member.Model.roleInfo roleMode = new ZG_member.Model.roleInfo();
                ZG_member.BLL.operatorInfo opera = new ZG_member.BLL.operatorInfo();
                ZG_member.Model.operatorInfo operaMode = new ZG_member.Model.operatorInfo();
                operaMode = opera.GetModelList("username='" + MainForm.Operator + "'")[0];
                roleMode = role.GetModel(Convert.ToInt32(operaMode.roleId));
                if (roleMode.roleInfo1[40].ToString() == "0")
                {
                    this.txtOpenTeacher.Enabled = false;
                }
                this.linkLabel1.Visible = false;
                this.txtMenberId.Text = mb.memberId;
                this.txtMenberName.Text = mb.memberName;
                this.cbxMarriage.Text = mb.Marriage;
                areaMode = area.getModel(mb.AreasID);
                this.cbxArea.Text = areaMode.AreaName;
                this.cmbType.Enabled = false;
                this.txtAddress.Text = mb.Address;
                this.txtQQ.Text = mb.QQ;
                this.txtZip.Text = mb.Zip;
                this.txthobby.Text = mb.hobby;
                this.txtMemo.Text = mb.memo;
                var cardType = mb.cardType;
                string cardTypeStr = "";
                //if (cardType == 19)
                //{
                //    cardTypeStr = "金卡";
                //}
                //if (cardType == 34)
                //{
                //    cardTypeStr = "至尊卡";
                //}
                this.cmbType.Text = cm.GetModel(Convert.ToInt32(cardType)).solutionName;
                //this.cmbType.SelectedValue = mb.cardType;
                this.txtMobile.Text = mb.mobile;
                var sex = mb.sex;
                string sexStr = "";
                if (sex == true)
                {
                    sexStr = "男";
                }
                else
                {
                    sexStr = "女";
                }
                this.cbxsex.Text = sexStr;
                this.txtEmail.Text = mb.Email;
                this.txtIDNumber.Text = mb.IDNumber;
                this.txtTel.Text = mb.Tel;
                this.dateBirthday.Value = Convert.ToDateTime(mb.birthDay);
                this.dateExpiresDate.Value = Convert.ToDateTime(mb.expiresDate);
                var status = mb.status;
                string statuStr = "";
                if (status == 0)
                {
                    statuStr = "正常";
                }
                if (status == 1)
                {
                    statuStr = "挂失";
                }
                if (status == 2)
                {
                    statuStr = "停用";
                }
                this.cbxStatus.Text = statuStr;
                this.txtPoint.Text = mb.point.ToString();
                this.dateCreateDate.Text = mb.createDate.ToString();
                this.textBox1.Text = mb.id.ToString();
                this.txtProfession.Text = mb.Profession;
                this.txthobby.Text = mb.hobby;
                this.txtQQ.Text = mb.QQ;

                this.cbxChild.Text = mb.Child;
                this.txtUnit.Text = mb.Unit;
                this.txtOpenTeacher.Text = mb.OpenTeacher;
                string sPicPath = Application.StartupPath.Replace("bin\\Debug", "photo\\"+mb.picUrl);
                getPhoto(sPicPath);

            }
            else
            {  
                
                string sPicPath = Application.StartupPath.Replace("bin\\Debug", "photo\\员工.png");
                getPhoto(sPicPath);
                this.cbxArea.Text = "北京";
            }




            if (this.Text == "会员卡信息修改")
            {
                txtMenberId.Enabled = false;
                txtPoint.Enabled = false;
                txtpassword.Enabled = false;
                txtpassword1.Enabled = false;
            }

        }
        // 照片
        public void getPhoto(string path)
        {
            if (File.Exists(path))
            {
                Bitmap bmPic = new Bitmap(path);
                Point ptLoction = new Point(bmPic.Size);
                if (ptLoction.X < pictureBox1.Size.Width || ptLoction.Y > pictureBox1.Size.Height)
                {
                    pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
                }
                else
                {
                    pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
                }
                pictureBox1.ImageLocation = path;
                bmPic.Dispose();
            }
        }

        //读卡
        public bool ReadCard()
        {
            string contents = "";
            string status = vnp.RfidCardRequestAndReadData("1", "FFFFFFFFFFFF");
            if (status == "1")
            {
                //MessageBox.Show("机器未插卡");
            }
            else
                if (status == "0")
                {
                    MessageBox.Show("端口未打卡");
                }
                else
                {
                    //string data = "";
                    //byte blocknum = 1;
                    //VN.WriteData(blocknum, data);
                    //return;
                    //VN.ReadData(blocknum, ref data);
                    contents = status;
                    //id = this.TxtCardId.Text;
                }
            memberInfo mem = new memberInfo();
            ZG_member.Model.memberInfo memModel = new ZG_member.Model.memberInfo();
            DataTable memtb = mem.GetList("memberCardId='" + contents + "'").Tables[0];
            string ret = "";
            if (memtb.Rows.Count != 0)
            {
                return false;
            }
            return true;


        }


        //写卡
        public void WriteCard(string date)
        {
            string mima;
            try
            {
                //mima = vnp.ZSGW_KeyPass(vnp.RfidCardRequestAndReadNum());
                mima = "FFFFFFFFFFFF";
                vnp.RfidCardRequestAndWriteData("1", mima, date);
            }
            catch (Exception)
            {

                throw;
            }
        }

        string faxing = ConfigurationManager.AppSettings["faxin"];
        /// <summary>
        /// 添加和修改信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        SendMsgsForm sf = new SendMsgsForm();
        private void publishCardBtn_Click(object sender, EventArgs e)
        {
            if (this.txtMenberName.Text == "")
            {
                this.lbNameFK.Visible = true;
            }
            if (this.cbxsex.Text == "")
            {
                this.lbGenderFK.Visible = true;
            }
            if (this.dateBirthday.Text == "")
            {
                this.lbChushengFK.Visible = true;
            }
            if (this.txtOpenTeacher.Text == "")
            {
                this.lbOpenTeacherFK.Visible = true;
            }
            //if (this.txtTel.Text == "")
            //{
            //    this.lbTelFK.Visible = true;
            //}
            if (this.txtMenberName.Text == "")
            {
                this.lbNameFK.Visible = true;
            }
            if (this.Text != "会员卡信息修改" && this.Text != "用户信息修改")
            {
                //if (this.txtpassword.Text == "" || this.txtpassword1.Text == "")
                //{
                //    this.lbPassFK.Visible = true;
                //}
            }
            if (this.cbxArea.Text == "")
            {
                this.lbAreaFK.Visible = true;
            }
            if (this.lbNameFK.Visible == true || this.lbAreaFK.Visible == true || this.lbChushengFK.Visible == true || this.lbPassFK.Visible == true || this.lbGenderFK.Visible == true || this.lbTelFK.Visible == true || this.lbOpenTeacherFK.Visible == true)
            {
                return;
            }

            if (this.txtpassword.Text != this.txtpassword1.Text)
            {
                this.lbPassFK2.Visible = true;
                return;
            }
               #region 修改会员

            if (this.Text == "会员卡信息修改" || this.Text == "用户信息修改")
            {
                memberInfo menInfo = new memberInfo();
                Model.memberInfo menInfoMod = new Model.memberInfo();
                Areas area = new Areas();
                Model.Areas areaMode = new Model.Areas();

                menInfoMod = menInfo.GetModel(UpdateId);
                //bool aaa = menInfo.ExistsByphone(this.txtTel.Text, this.txtMenberId.Text);
                //if (aaa)
                //{
                //    MessageBox.Show("一个手机号只能绑定一张卡，请重新输入");
                //    return;
                //}
                if (txtPoint.Text == string.Empty)
                {
                    txtPoint.Text = "0";
                }


                menInfoMod.memberId = txtMenberId.Text.Trim();
                menInfoMod.memberName = txtMenberName.Text.Trim();
                if (cbxsex.Text.Trim() == "男")
                {
                    menInfoMod.sex = true;
                }
                else
                {
                    menInfoMod.sex = false;
                }
                menInfoMod.id = Convert.ToInt32(this.textBox1.Text);
                menInfoMod.mobile = txtMobile.Text.Trim();
                menInfoMod.Tel = txtTel.Text.Trim();
                menInfoMod.Email = txtEmail.Text.Trim();
                menInfoMod.IDNumber = txtIDNumber.Text.Trim();
                menInfoMod.birthDay = DateTime.Parse(dateBirthday.Text.Trim());
                menInfoMod.Marriage = cbxMarriage.Text;
                menInfoMod.Zip = this.txtZip.Text;
                menInfoMod.Address = txtAddress.Text;
                string areaName = this.cbxArea.Text;
                areaMode = area.getModelToString(areaName);
                menInfoMod.AreasID = areaMode.id;


                /// <summary>
                /// 获得卡片类型对应表的id
                /// </summary>
                consumeSolution consume = new consumeSolution();
                Model.consumeSolution consumeMod = new Model.consumeSolution();
                consumeMod = consume.GetModelList("solutionName='" + cmbType.Text.Trim() + "'")[0];
                menInfoMod.cardType = consumeMod.id;
                goods gd = new goods();
                menInfoMod.Balance = mb.Balance; ;
                menInfoMod.point = int.Parse(txtPoint.Text.Trim());
                if (cbxStatus.Text.Trim() == "正常")
                {
                    menInfoMod.status = int.Parse("0");
                }
                if (cbxStatus.Text.Trim() == "挂失")
                {
                    menInfoMod.status = int.Parse("1");
                }
                if (cbxStatus.Text.Trim() == "停用")
                {
                    menInfoMod.status = int.Parse("2");
                }
                if (updatePic)
                {
                    string replace = Application.StartupPath.Replace("bin\\Debug", "photo");
                    DirectoryInfo ddir = new DirectoryInfo(replace);
                    FileInfo[] dfiles = ddir.GetFiles();
                    if (menInfoMod.picUrl != "员工.png")
                    {
                        for (int i = 0; i < dfiles.Length; i++)
                        {
                            if (dfiles[i].ToString() == menInfoMod.picUrl)
                            {
                                File.Delete(Application.StartupPath.Replace("bin\\Debug", "photo\\" + dfiles[i].ToString()));
                            }
                        }
                    }
                    menInfoMod.picUrl = picName;
                }
                menInfoMod.createDate = DateTime.Parse(dateCreateDate.Text.Trim());
                menInfoMod.expiresDate = DateTime.Parse(dateExpiresDate.Text.Trim());
                menInfoMod.memo = txtMemo.Text.Trim();
                menInfoMod.Profession = this.txtProfession.Text;
                menInfoMod.hobby = this.txthobby.Text;
                menInfoMod.QQ = this.txtQQ.Text;
                menInfoMod.Child = this.cbxChild.Text;
                menInfoMod.Unit = this.txtUnit.Text;
                menInfoMod.OpenTeacher = this.txtOpenTeacher.Text;
                if (menInfo.Update(menInfoMod))
                {
                    string str = "修改成功";
                    if (id != "0")
                    {
                        string x;
                        //**************************
                        if (id != "0")
                        {
                            DialogResult dt = MessageBox.Show("是否打印？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
                            if (dt == DialogResult.Yes)
                            {

                                string mima = "";
                                string status = "";
                                try
                                {
                                    string strReturn = vnp.RfidCardRequestAndReadNum();
                                    if (strReturn == "1")
                                    {
                                        MessageBox.Show("机器内没有卡，请插卡");
                                        return;
                                    }
                                    else
                                    {
                                        mima = vnp.ZSGW_KeyPass(vnp.RfidCardRequestAndReadNum());
                                        //mima = "FFFFFFFFFFFF";
                                        status = vnp.RfidCardRequestAndReadData("1", mima);
                                    }
                                }
                                catch (Exception)
                                {

                                    MessageBox.Show("此卡不是本公司的卡片！请与本公司联系。电话：010-51291008");
                                    return;
                                }

                                if (status == "0" || status == "1")
                                {


                                    MessageBox.Show("机器内没有卡，请插卡");
                                    return;
                                }
                                MemberSaleForm ms = new MemberSaleForm(mainForm, menInfoMod.memberCardId, this.txtMenberId.Text, vnp);
                                double memberBalance = Math.Round(Convert.ToDouble(menInfoMod.Balance), 2);
                                //string[] ModelArray = new string[] { this.txtMenberId.Text, this.cmbType.Text, this.txtMenberName.Text, this.cbxsex.Text, this.cbxStatus.Text, this.dateCreateDate.Text, this.dateExpiresDate.Text, "0", "0", "0"};
                                string[] ModelArray = new string[] { this.txtMenberId.Text, this.cmbType.Text, this.txtMenberName.Text, this.cbxsex.Text, this.cbxStatus.Text, this.dateCreateDate.Text, this.dateExpiresDate.Text, "0", "0", "0", "0", memberBalance.ToString(), "0", memberBalance.ToString(), "0", "0", "" };

                                string Go = ms.print(ModelArray);
                                Go = "\n" + Go;
                                Model.memberInfo mode = ms.GetModel();
                                int Nowday = DateTime.Now.Day;
                                int Nowyue = DateTime.Now.Month;

                                int shengriday = ((DateTime)mode.birthDay).Day;
                                int shengriyue = ((DateTime)mode.birthDay).Month;
                                birthdayremind br = new birthdayremind();
                                Model.birthdayremind brmodl = br.GetModel(2);
                                int aa = br.tixingday(this.txtMenberId.Text);
                                if (aa < brmodl.Remindday && aa != 0)
                                {
                                    if (Nowyue == shengriyue)
                                    {
                                        if (Nowday < shengriday)
                                        {
                                            string one = brmodl.Remindcontent.Replace("{now}", DateTime.Now.ToString("yyyy-MM-dd") + "\n");
                                            string two = one.Replace("{leftDays}", aa.ToString());
                                            Go += two + "\n";
                                        }
                                    }
                                    if (Nowyue < shengriyue)
                                    {
                                        string one = brmodl.Remindcontent.Replace("{now}", DateTime.Now.ToString("yyyy-MM-dd") + "\n");
                                        string two = one.Replace("{leftDays}", aa.ToString());
                                        Go += two + "\n";
                                    }
                                }
                                else if (aa == 0)
                                {
                                    Go += ms.AdvPreProcess(brmodl.Nowremindcontent1) + "\n";
                                }
                                vnp.PrintBufferClear();
                                Application.DoEvents();
                                vnp.PrintCharacterDataSetting(Go);
                                Application.DoEvents();
                                vnp.ErasePrintDischarge3();
                            }
                        }
                        //***************

                        //x = Convert.ToString((Convert.ToInt32(Write) + 1)).PadLeft(8, '0');
                        //StreamWriter sw = new StreamWriter("nextCardNumber.ini", false, Encoding.GetEncoding("gb2312"));
                        //sw.Flush();
                        //sw.Write(x);
                        //sw.Close();
                    }
                    if (this.cbxStatus.Text == "停用")
                    {
                        str += ",卡内余额还有:" + menInfoMod.Balance.ToString() + "元。";
                    }
                    MessageBox.Show(str);
                    mainForm.shifouxianshi(MainForm.Operator);

                    this.Close();
                }
                else
                {
                    MessageBox.Show("修改失败");
                }

            #endregion
            }
            else
            {
                if (this.Text=="添加会员")
                {
                    #region 添加会员


                    string mima;
                    string status;
                   
                    try
                    {
                        string strReturn = vnp.RfidCardRequestAndReadNum();

                        if (strReturn == "1")
                        {
                            MessageBox.Show("机器内没有卡，请插卡");
                            return;
                        }
                        else
                        {
                            mima = vnp.ZSGW_KeyPass(vnp.RfidCardRequestAndReadNum());
                            //mima ="FFFFFFFFFFFF";
                            status = vnp.RfidCardRequestAndReadData("1", mima);
                            this.txtCardId.Text = status;
                            if (txtCardId.Text.Trim() == "")
                            {
                                
                            }
                        }
                    }
                    catch (Exception)
                    {

                        MessageBox.Show("此卡不是本公司的卡片！请与本公司联系。电话：010-51291008");
                        return;
                    }

                    if (status == "0" || status == "1")
                    {


                        MessageBox.Show("机器内没有卡，请插卡");
                    }

                    else
                    {
                        memberInfo memberBLL = new memberInfo();
                        Model.memberInfo memberModel = new Model.memberInfo();
                        DataTable dts = memberBLL.GetList(" memberCardId='" + status + "' ").Tables[0];
                        if (dts.Rows.Count==1)
                        {
                            MessageBox.Show("此卡已被发过,无法再次发卡");
                        }

                        else
                        {
                            
                            memberInfo menInfo = new memberInfo();
                            Model.memberInfo menInfoMod = new Model.memberInfo();
                            //bool aaa = menInfo.ExistsByphone(this.txtTel.Text, this.txtMenberId.Text);
                            //if (aaa)
                            //{
                            //    MessageBox.Show("一个手机号只能绑定一张卡，请重新输入");
                            //    return;
                            //}


                            if (txtPoint.Text == string.Empty)
                            {
                                txtPoint.Text = "0";
                            }


                            menInfoMod.memberId = txtMenberId.Text.Trim();
                            menInfoMod.memberName = txtMenberName.Text.Trim();

                            if (txtpassword.Text.Trim() != "")
                            {
                                MD5 md5 = new MD5CryptoServiceProvider();
                                byte[] bt = Encoding.Default.GetBytes(txtpassword.Text);
                                bt = md5.ComputeHash(bt);
                                menInfoMod.pwd = BitConverter.ToString(bt).Replace("-", "");
                            }
                            else
                            {
                                menInfoMod.pwd = null;
                            }


                            if (cbxsex.Text.Trim() == "男")
                            {
                                menInfoMod.sex = true;
                            }
                            else
                            {
                                menInfoMod.sex = false;
                            }
                            Areas area = new Areas();
                            Model.Areas areaMode = new Model.Areas();
                            //menInfoMod.memberCardId = GetNumber(DateTime.Now.ToString());
                            menInfoMod.memberCardId = GetNumber(DateTime.Now.ToString());
                            menInfoMod.mobile = txtMobile.Text.Trim();
                            menInfoMod.Tel = txtTel.Text.Trim();
                            menInfoMod.Email = txtEmail.Text.Trim();
                            menInfoMod.IDNumber = txtIDNumber.Text.Trim();
                            menInfoMod.birthDay = DateTime.Parse(dateBirthday.Text.Trim());
                            menInfoMod.Marriage = cbxMarriage.Text;
                            menInfoMod.Zip = txtZip.Text;
                            menInfoMod.Address = txtAddress.Text;
                            string areaName = this.cbxArea.Text;
                            areaMode = area.getModelToString(areaName);
                            menInfoMod.AreasID = areaMode.id;
                            menInfoMod.Profession = this.txtProfession.Text;
                            menInfoMod.hobby = this.txthobby.Text;
                            menInfoMod.QQ = this.txtQQ.Text;
                            menInfoMod.Child = this.cbxChild.Text;
                            menInfoMod.Unit = this.txtUnit.Text;
                            menInfoMod.OpenTeacher = this.txtOpenTeacher.Text;

                            /// <summary>
                            /// 获得卡片类型对应表的id
                            /// </summary>
                            consumeSolution consume = new consumeSolution();
                            Model.consumeSolution consumeMod = new Model.consumeSolution();
                            consumeMod = consume.GetModelList("solutionName='" + cmbType.Text + "'")[0];
                            menInfoMod.cardType = consumeMod.id;
                            //goods gd = new goods();
                            //string [] taocan= consumeMod.Taocanxiangqing.Split('|');
                            //decimal memberBalance = 0;
                            //for (int i = 0; i < taocan.Count()-1; i++)
                            //{
                            //    decimal danjia = Convert.ToDecimal(gd.getModelGoodsIdString(taocan[i].Substring(0, consumeMod.Taocanxiangqing.IndexOf(','))).price);
                            //    int shuliang =Convert.ToInt32(taocan[i].Substring(taocan[i].IndexOf(',')+1));
                            //    memberBalance += danjia * shuliang;

                            //}


                            //menInfoMod.Balance = memberBalance;
                            int memberBalance = 0;
                            menInfoMod.Balance = memberBalance;


                            menInfoMod.point = int.Parse(txtPoint.Text.Trim());
                            if (cbxStatus.Text.Trim() == "正常")
                            {
                                menInfoMod.status = int.Parse("0");
                            }
                            if (cbxStatus.Text.Trim() == "挂失")
                            {
                                menInfoMod.status = int.Parse("1");
                            }
                            if (cbxStatus.Text.Trim() == "停用")
                            {
                                menInfoMod.status = int.Parse("2");
                            }
                            menInfoMod.createDate = DateTime.Parse(dateCreateDate.Text.Trim());
                            menInfoMod.expiresDate = DateTime.Parse(dateExpiresDate.Text.Trim());
                            menInfoMod.memo = txtMemo.Text.Trim();

                            menInfoMod.consume = 0;
                            menInfoMod.picUrl = picName;
                            int row = menInfo.Add(menInfoMod);
                            if (row > 0)
                            {

                                Model.taocanjilu tcmodle = new Model.taocanjilu();
                                tcmodle.Memberid = this.txtMenberId.Text.Trim();
                                tcmodle.Xiangqing = consumeMod.Taocanxiangqing;
                                taocanjiluBLL tcbll = new taocanjiluBLL();
                                if (!tcbll.Exists(this.txtMenberId.Text.Trim()))
                                {
                                    tcbll.Add(tcmodle);
                                }
                                WriteCard(menInfoMod.memberCardId);
                                if (shoushu == false)
                                {
                                    StreamWriter sw = new StreamWriter("memberCardId.ini", false, Encoding.GetEncoding("gb2312"));
                                    sw.Flush();
                                    sw.Write(this.txtMenberId.Text);
                                    sw.Close();
                                }
                                MemberSaleForm ms = new MemberSaleForm(mainForm,menInfoMod.memberCardId, this.txtMenberId.Text, vnp);
                                Model.memberInfo mode = ms.GetModel();
                                int Nowday = DateTime.Now.Day;
                                int Nowyue = DateTime.Now.Month;
                                string nowdays = Nowday.ToString();
                                string nowyues = Nowyue.ToString();
                                int shengriday = ((DateTime)mode.birthDay).Day;
                                int shengriyue = ((DateTime)mode.birthDay).Month;
                                //MainForm.cardtype = this.cmbType.SelectedValue.ToString();
                                //string[] ModelArray = new string[] { this.txtMenberId.Text, this.cmbType.Text, this.txtMenberName.Text, this.cbxsex.Text, this.cbxStatus.Text, this.dateCreateDate.Text, this.dateExpiresDate.Text, "0", "0", "0", "0", memberBalance.ToString(), "0", memberBalance.ToString(), "0", "0","", this.Semester.Text, this.Course.Text };
                                //"会员卡号#卡片类型                                                              #会员姓名                     #性　　别              #卡片状态#办卡日期                     #截止日期#累计积分#本次积分#可用积分#本次消费#储值余额#折扣金额#本次充值#积分支付#现金消费#空　　行"
                                string[] ModelArray = new string[] { this.txtMenberId.Text, this.cmbType.Text, this.txtMenberName.Text, this.cbxsex.Text, this.cbxStatus.Text, this.dateCreateDate.Text, this.dateExpiresDate.Text, "0", "0", "0", "0", memberBalance.ToString(), "0", memberBalance.ToString(), "0", "0", "" };
                                string Go = ms.print(ModelArray);
                                Go = "\n" + Go;
                                birthdayremind br = new birthdayremind();
                                Model.birthdayremind brmodl = br.GetModel(2);
                                int aa = br.tixingday(this.txtMenberId.Text);
                                if (aa <= brmodl.Remindday && aa != 0)
                                {
                                    if (Nowyue == shengriyue)
                                    {
                                        if (Nowday < shengriday)
                                        {
                                            string one = brmodl.Remindcontent.Replace("{now}", DateTime.Now.ToString("yyyy-MM-dd") + "\n");
                                            string two = one.Replace("{leftDays}", aa.ToString());
                                            Go += two + "\n";
                                        }
                                    }
                                    if (Nowyue < shengriyue)
                                    {
                                        string one = brmodl.Remindcontent.Replace("{now}", DateTime.Now.ToString("yyyy-MM-dd") + "\n");
                                        string two = one.Replace("{leftDays}", aa.ToString());
                                        Go += two + "\n";
                                    }
                                }
                                else if (aa == 0)
                                {
                                    Go += ms.AdvPreProcess(brmodl.Nowremindcontent1) + "\n";
                                }



                                //Go +="项目名             数量\n";

                                //string[] taocan2 = consumeMod.Taocanxiangqing.Split('|');
                                //for (int i = 0; i < taocan.Count() - 1; i++)
                                //{
                                //    string xiangmuming=gd.getModelGoodsIdString(taocan[i].Substring(0, consumeMod.Taocanxiangqing.IndexOf(','))).goodsName;

                                //    if (getStringLength(xiangmuming) >= 19)
                                //    {
                                //        xiangmuming = xiangmuming.Substring(0, 15) + "...";
                                //        Go += xiangmuming;
                                //    }
                                //    else
                                //    {
                                //        Go += xiangmuming;
                                //        for (int q = 0; q < 19-getStringLength(xiangmuming); q++)
                                //        {
                                //            Go += " ";
                                //        }
                                //    }
                                //    int shuliang = Convert.ToInt32(taocan[i].Substring(taocan[i].IndexOf(',') + 1));
                                //    Go += shuliang + "\n";

                                //}






















                                //BLL.Duanxingneirong blldx = new Duanxingneirong();
                                //Model.Duanxingneirong dxmodle =  blldx.getmodel(1);
                                //string fakaneirong = string.Format(dxmodle.Fasongneirong, this.cmbType.Text);
                                //fakaneirong += "【国金黄金】";
                                //try
                                //{
                                //    if (faxing == "1")
                                //    {
                                //        sf.sendMsg(fakaneirong, this.txtTel.Text);
                                //    }

                                //}
                                //catch (Exception)
                                //{
                                //    MessageBox.Show("由于计算机未连网，不能发信息！");

                                //}

                                DialogResult dt = MessageBox.Show("是否打印？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
                                if (dt == DialogResult.Yes)
                                {
                                    vnp.PrintBufferClear();
                                    Application.DoEvents();
                                    vnp.PrintCharacterDataSetting(Go);
                                    Application.DoEvents();
                                    vnp.ErasePrintDischarge3();
                                }
                                //储值记录
                                ZG_member.Model.wasteBook wbMode = new ZG_member.Model.wasteBook();
                                wasteBook wb = new wasteBook();

                                wbMode.operatorId = userName;
                                wbMode.memberCardId = this.txtMenberId.Text;
                                wbMode.date = DateTime.Now;
                                wbMode.consumeType = Convert.ToInt32(cmbType.SelectedValue);
                                wbMode.consumeMoney = 0;
                                wbMode.cardPayMoney = Convert.ToDecimal(0);
                                wbMode.cashPayMoney = Convert.ToDecimal(0);
                                wbMode.cardBalance = Convert.ToDecimal(0);
                                wbMode.refundmentMoney = Convert.ToDecimal(0);
                                wbMode.refundmentIntegral = 0;
                                wbMode.exchangeIntegral = 0;
                                wbMode.consumeIntegral = 0;
                                wbMode.totalIntegral = Convert.ToInt32(txtPoint.Text);
                                wbMode.savingMoney = Convert.ToDecimal(consumeMod.money);
                                wbMode.details="发卡";
                                wbMode.Discount = 100;
                                wb.Add(wbMode);
                                ////消费金额
                                //ZG_member.Model.wasteBook wbMode2 = new ZG_member.Model.wasteBook();
                                //wbMode2.operatorId = userName;
                                //wbMode2.memberCardId = this.txtMenberId.Text;
                                //wbMode2.date = DateTime.Now;
                                //wbMode2.consumeType = Convert.ToInt32(cmbType.SelectedValue);
                                //wbMode2.consumeMoney = Convert.ToDecimal(consumeMod.money);
                                //wbMode2.cardPayMoney = Convert.ToDecimal(consumeMod.money);
                                //wbMode2.cashPayMoney = Convert.ToDecimal(0);
                                //wbMode2.cardBalance = Convert.ToDecimal(0);
                                //wbMode2.refundmentMoney = Convert.ToDecimal(0);
                                //wbMode2.refundmentIntegral = 0;
                                //wbMode2.exchangeIntegral = 0;
                                //wbMode2.consumeIntegral = 0;
                                //wbMode2.totalIntegral = Convert.ToInt32(txtPoint.Text);
                                //wbMode2.savingMoney = 0;
                                //wb.Add(wbMode2);

                                ZG_member.BLL.SalesStaffList sale = new ZG_member.BLL.SalesStaffList();
                                ZG_member.Model.SalesStaffList saleMode = new ZG_member.Model.SalesStaffList();
                                ZG_member.BLL.SalesWasteBook saleWaste = new ZG_member.BLL.SalesWasteBook();
                                ZG_member.Model.SalesWasteBook saleWasteMode = new ZG_member.Model.SalesWasteBook();
                                saleMode = sale.GetModel(menInfoMod.OpenTeacher);
                                saleMode.Money += consumeMod.money;
                                sale.Update(saleMode);
                                saleWasteMode.SalesPersonId = saleMode.SalesPersonId;
                                saleWasteMode.Dates = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"));
                                saleWasteMode.Source = "充值";
                                saleWasteMode.money = consumeMod.money;
                                saleWasteMode.memberId = menInfoMod.memberId;
                                saleWaste.add(saleWasteMode);
                                MessageBox.Show("添加成功");
                                //string x;

                                //x = Convert.ToString((Convert.ToInt32(Write) + 1)).PadLeft(7, '0');
                                //StreamWriter sw = new StreamWriter("nextCardNumber.ini", false, Encoding.GetEncoding("gb2312"));
                                //sw.Flush();
                                //sw.Write(x);
                                //sw.Close();
                                mainForm.shifouxianshi(MainForm.Operator);
                                this.Close();
                            }
                            else
                            {
                                MessageBox.Show("添加失败");
                            }

                        }
                    }
                    #endregion
                }
                else if (memberId != "0")
                {
                    #region 添加用户
                      memberInfo menInfo = new memberInfo();
                            Model.memberInfo menInfoMod = new Model.memberInfo();
                            //bool aaa = menInfo.ExistsByphone(this.txtTel.Text, this.txtMenberId.Text);
                            //if (aaa)
                            //{
                            //    MessageBox.Show("一个手机号只能绑定一张卡，请重新输入");
                            //    return;
                            //}


                            if (txtPoint.Text == string.Empty)
                            {
                                txtPoint.Text = "0";
                            }


                            menInfoMod.memberId = txtMenberId.Text.Trim();
                            menInfoMod.memberName = txtMenberName.Text.Trim();

                            if (txtpassword.Text.Trim() != "")
                            {
                                MD5 md5 = new MD5CryptoServiceProvider();
                                byte[] bt = Encoding.Default.GetBytes(txtpassword.Text);
                                bt = md5.ComputeHash(bt);
                                menInfoMod.pwd = BitConverter.ToString(bt).Replace("-", "");
                            }
                            else
                            {
                                menInfoMod.pwd = null;
                            }


                            if (cbxsex.Text.Trim() == "男")
                            {
                                menInfoMod.sex = true;
                            }
                            else
                            {
                                menInfoMod.sex = false;
                            }
                            Areas area = new Areas();
                            Model.Areas areaMode = new Model.Areas();
                            //menInfoMod.memberCardId = GetNumber(DateTime.Now.ToString());
                            menInfoMod.memberCardId ="";
                            menInfoMod.mobile = txtMobile.Text.Trim();
                            menInfoMod.Tel = txtTel.Text.Trim();
                            menInfoMod.Email = txtEmail.Text.Trim();
                            menInfoMod.IDNumber = txtIDNumber.Text.Trim();
                            menInfoMod.birthDay = DateTime.Parse(dateBirthday.Text.Trim());
                            menInfoMod.Marriage = cbxMarriage.Text;
                            menInfoMod.Zip = txtZip.Text;
                            menInfoMod.Address = txtAddress.Text;
                            string areaName = this.cbxArea.Text;
                            areaMode = area.getModelToString(areaName);
                            menInfoMod.AreasID = areaMode.id;
                            menInfoMod.Profession = this.txtProfession.Text;
                            menInfoMod.hobby = this.txthobby.Text;
                            menInfoMod.QQ = this.txtQQ.Text;
                            menInfoMod.Child = this.cbxChild.Text;
                            menInfoMod.Unit = this.txtUnit.Text;
                            menInfoMod.OpenTeacher = this.txtOpenTeacher.Text;

                            /// <summary>
                            /// 获得卡片类型对应表的id
                            /// </summary>
                            consumeSolution consume = new consumeSolution();
                            Model.consumeSolution consumeMod = new Model.consumeSolution();
                            consumeMod = consume.GetModelList("solutionName='" + cmbType.Text + "'")[0];
                            menInfoMod.cardType = consumeMod.id;
                            //goods gd = new goods();
                            //string [] taocan= consumeMod.Taocanxiangqing.Split('|');
                            //decimal memberBalance = 0;
                            //for (int i = 0; i < taocan.Count()-1; i++)
                            //{
                            //    decimal danjia = Convert.ToDecimal(gd.getModelGoodsIdString(taocan[i].Substring(0, consumeMod.Taocanxiangqing.IndexOf(','))).price);
                            //    int shuliang =Convert.ToInt32(taocan[i].Substring(taocan[i].IndexOf(',')+1));
                            //    memberBalance += danjia * shuliang;

                            //}


                            //menInfoMod.Balance = memberBalance;
                            int memberBalance = 0;
                            menInfoMod.Balance = memberBalance;


                            menInfoMod.point = int.Parse(txtPoint.Text.Trim());
                            if (cbxStatus.Text.Trim() == "正常")
                            {
                                menInfoMod.status = int.Parse("0");
                            }
                            if (cbxStatus.Text.Trim() == "挂失")
                            {
                                menInfoMod.status = int.Parse("1");
                            }
                            if (cbxStatus.Text.Trim() == "停用")
                            {
                                menInfoMod.status = int.Parse("2");
                            }
                            menInfoMod.createDate = DateTime.Parse(dateCreateDate.Text.Trim());
                            menInfoMod.expiresDate = DateTime.Parse(dateExpiresDate.Text.Trim());
                            menInfoMod.memo = txtMemo.Text.Trim();

                            menInfoMod.consume = 0;
                            int row = menInfo.Add(menInfoMod);
                            if (row > 0)
                            {

                                Model.taocanjilu tcmodle = new Model.taocanjilu();
                                tcmodle.Memberid = this.txtMenberId.Text.Trim();
                                tcmodle.Xiangqing = consumeMod.Taocanxiangqing;
                                taocanjiluBLL tcbll = new taocanjiluBLL();
                                if (!tcbll.Exists(this.txtMenberId.Text.Trim()))
                                {
                                    tcbll.Add(tcmodle);
                                }

                                //if (shoushu == false)
                                //{
                                //    StreamWriter sw = new StreamWriter("memberCardId.ini", false, Encoding.GetEncoding("gb2312"));
                                //    sw.Flush();
                                //    sw.Write(this.txtMenberId.Text);
                                //    sw.Close();
                                //}
                                MemberSaleForm ms = new MemberSaleForm(mainForm,menInfoMod.memberCardId, this.txtMenberId.Text, vnp);
                                Model.memberInfo mode = ms.GetModel();
                                int Nowday = DateTime.Now.Day;
                                int Nowyue = DateTime.Now.Month;
                                string nowdays = Nowday.ToString();
                                string nowyues = Nowyue.ToString();
                                int shengriday = ((DateTime)mode.birthDay).Day;
                                int shengriyue = ((DateTime)mode.birthDay).Month;
                                //MainForm.cardtype = this.cmbType.SelectedValue.ToString();
                                //string[] ModelArray = new string[] { this.txtMenberId.Text, this.cmbType.Text, this.txtMenberName.Text, this.cbxsex.Text, this.cbxStatus.Text, this.dateCreateDate.Text, this.dateExpiresDate.Text, "0", "0", "0", "0", memberBalance.ToString(), "0", memberBalance.ToString(), "0", "0","", this.Semester.Text, this.Course.Text };
                                //"会员卡号#卡片类型                                                              #会员姓名                     #性　　别              #卡片状态#办卡日期                     #截止日期#累计积分#本次积分#可用积分#本次消费#储值余额#折扣金额#本次充值#积分支付#现金消费#空　　行"
                                //储值记录
                                ZG_member.Model.wasteBook wbMode = new ZG_member.Model.wasteBook();
                                wasteBook wb = new wasteBook();

                                wbMode.operatorId = userName;
                                wbMode.memberCardId = this.txtMenberId.Text;
                                wbMode.date = DateTime.Now;
                                wbMode.consumeType = Convert.ToInt32(cmbType.SelectedValue);
                                wbMode.consumeMoney = 0;
                                wbMode.cardPayMoney = Convert.ToDecimal(0);
                                wbMode.cashPayMoney = Convert.ToDecimal(0);
                                wbMode.cardBalance = Convert.ToDecimal(0);
                                wbMode.refundmentMoney = Convert.ToDecimal(0);
                                wbMode.refundmentIntegral = 0;
                                wbMode.exchangeIntegral = 0;
                                wbMode.consumeIntegral = 0;
                                wbMode.totalIntegral = Convert.ToInt32(txtPoint.Text);
                                wbMode.savingMoney = Convert.ToDecimal(consumeMod.money);
                                wb.Add(wbMode);
                                //消费金额
                                ZG_member.Model.wasteBook wbMode2 = new ZG_member.Model.wasteBook();
                                wbMode2.operatorId = userName;
                                wbMode2.memberCardId = this.txtMenberId.Text;
                                wbMode2.date = DateTime.Now;
                                wbMode2.consumeType = Convert.ToInt32(cmbType.SelectedValue);
                                wbMode2.consumeMoney = Convert.ToDecimal(consumeMod.money);
                                wbMode2.cardPayMoney = Convert.ToDecimal(consumeMod.money);
                                wbMode2.cashPayMoney = Convert.ToDecimal(0);
                                wbMode2.cardBalance = Convert.ToDecimal(0);
                                wbMode2.refundmentMoney = Convert.ToDecimal(0);
                                wbMode2.refundmentIntegral = 0;
                                wbMode2.exchangeIntegral = 0;
                                wbMode2.consumeIntegral = 0;
                                wbMode2.totalIntegral = Convert.ToInt32(txtPoint.Text);
                                wbMode2.savingMoney = 0;
                                wb.Add(wbMode2);

                                ZG_member.BLL.SalesStaffList sale = new ZG_member.BLL.SalesStaffList();
                                ZG_member.Model.SalesStaffList saleMode = new ZG_member.Model.SalesStaffList();
                                ZG_member.BLL.SalesWasteBook saleWaste = new ZG_member.BLL.SalesWasteBook();
                                ZG_member.Model.SalesWasteBook saleWasteMode = new ZG_member.Model.SalesWasteBook();
                                saleMode = sale.GetModel(menInfoMod.OpenTeacher);
                                saleMode.Money += consumeMod.money;
                                sale.Update(saleMode);
                                saleWasteMode.SalesPersonId = saleMode.SalesPersonId;
                                saleWasteMode.Dates = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"));
                                saleWasteMode.Source = "充值";
                                saleWasteMode.money = consumeMod.money;
                                saleWasteMode.memberId = menInfoMod.memberId;
                                saleWaste.add(saleWasteMode);
                                MessageBox.Show("添加成功");
                                //string x;

                                //x = Convert.ToString((Convert.ToInt32(Write) + 1)).PadLeft(7, '0');
                                //StreamWriter sw = new StreamWriter("nextCardNumber.ini", false, Encoding.GetEncoding("gb2312"));
                                //sw.Flush();
                                //sw.Write(x);
                                //sw.Close();
                                mainForm.shifouxianshi(MainForm.Operator);
                                this.Close();
                            }
                            else
                            {
                                MessageBox.Show("添加失败");
                            }

                    #endregion

                }
                    
            }
        }

        /// <summary>
        /// 重填信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void resetBtn_Click(object sender, EventArgs e)
        {

            for (int i = 0; i < this.Controls.Count; i++)
            {

                Control a = this.Controls[i];
                if (a.Enabled != false)
                {
                    if (a is TextBox || a is ComboBox)
                    {
                        this.Controls[i].Text = "";
                    }
                }
            }

        }

        private void cancelBtn_Click(object sender, EventArgs e)
        {
            this.timer2.Start();

        }

        private void button1_Click(object sender, EventArgs e)
        {
            //  txtMenberId.Text= CardHelper.NewNumber();
        }
        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {

            memberInfo mi = new memberInfo();
            string IniMemberCardId = "";
            if (this.Text == "添加会员")
            {
                StreamReader sr = new StreamReader("memberCardId.ini", Encoding.GetEncoding("gb2312"));
                if (sr.Peek() >= 0)
                {
                    IniMemberCardId = (Convert.ToInt32(sr.ReadLine()) + 1).ToString();
                }
                else
                {
                }
                sr.Close();
            }
            else if(this.Text=="添加用户")
            {
                IniMemberCardId = mi.GetMaxmemberId();
            }

          
            string aa = IniMemberCardId;
            if (aa == "")
            {
                aa = "000001";
            }
            else
            {
                aa = aa.PadLeft(8, '0');
            }
            aa = aa.Replace('4', '5');
            if (mi.GetList("memberId='" + aa + "'").Tables[0].Rows.Count > 0)
            {
                aa = (Convert.ToInt32(aa) + 1).ToString();
                aa = aa.PadLeft(8, '0');
            }
            if (this.Text == "添加用户")
            {
                aa = "8" + aa.Substring(1);
            }
            this.txtMenberId.Text = aa;


            tianjiayanzheng();
            shoushu = false;


        }
        string temp = "";


        /// <summary>
        /// 封装用户输入的信息
        /// </summary>
        /// <returns></returns>

        /// <summary>
        /// 打印
        /// </summary>
        /// <param name="printer"></param>
        /// <param name="strText"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="direction"></param>
        /// <param name="fontname"></param>
        /// <param name="fontsize"></param>
        /// <returns></returns>



       


        private void timer1_Tick(object sender, EventArgs e)
        {
            this.Left += 2;
            this.Opacity += 0.1;
            if (Opacity == 1)
            {
                this.timer1.Stop();

            }
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            this.Top = this.Top + 10;
            this.Opacity = this.Opacity - 0.06;
            if (Opacity <= 0)
            {
                this.timer2.Stop();
                this.Close();
            }


        }

        private void txtTel_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!(((e.KeyChar >= '0') && (e.KeyChar <= '9')) || e.KeyChar <= 31))
            {
                if (e.KeyChar == '.')
                {
                    if (((TextBox)sender).Text.Trim().IndexOf('.') > -1)
                        e.Handled = true;
                }
                else
                    e.Handled = true;
            }
            else
            {
                if (e.KeyChar <= 31)
                {
                    e.Handled = false;
                }
                else if (((TextBox)sender).Text.Trim().IndexOf('.') > -1)
                {
                    if (((TextBox)sender).Text.Trim().Substring(((TextBox)sender).Text.Trim().IndexOf('.') + 1).Length >= 4)
                        e.Handled = true;
                }
            }

        }

        private void txtPoint_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!(((e.KeyChar >= '0') && (e.KeyChar <= '9')) || e.KeyChar <= 31))
            {
                if (e.KeyChar == '.')
                {
                    if (((TextBox)sender).Text.Trim().IndexOf('.') > -1)
                        e.Handled = true;
                }
                else
                    e.Handled = true;
            }
            else
            {
                if (e.KeyChar <= 31)
                {
                    e.Handled = false;
                }
                else if (((TextBox)sender).Text.Trim().IndexOf('.') > -1)
                {
                    if (((TextBox)sender).Text.Trim().Substring(((TextBox)sender).Text.Trim().IndexOf('.') + 1).Length >= 4)
                        e.Handled = true;
                }
            }
        }

        private void txtMobile_KeyPress(object sender, KeyPressEventArgs e)
        {

        }
        int flag = 0;
        private void publishCardForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (flag == 0)
            {
                e.Cancel = true;
                flag = 1;
                this.timer2.Start();
            }
        }

        private void cbxArea_TextChanged(object sender, EventArgs e)
        {
            //if (id == "0")
            //{
            //    string name = this.cbxArea.Text;

            //    ZG_member.BLL.Areas area = new ZG_member.BLL.Areas();
            //    ZG_member.Model.Areas areaMode = new ZG_member.Model.Areas();
            //    string AreasName = name;
            //    areaMode = area.getModelToString(AreasName);
            //    ZG_member.BLL.memberInfo member = new ZG_member.BLL.memberInfo();
            //    ZG_member.Model.memberInfo memberMode = new ZG_member.Model.memberInfo();
            //    DataTable dt = member.GetListSql("select memberId from memberInfo where id in (select MAX(id)from memberInfo)").Tables[0];
            //    string maxMemberId = "";
            //    if (dt.Rows.Count > 0)
            //    {
            //         maxMemberId = dt.Rows[0][0].ToString();
            //    }
            //    else
            //    {
            //         maxMemberId = "8881010000000000"; 
            //    }
            //    maxMemberId = maxMemberId.Substring(8, maxMemberId.Length - 8);

            //    int memberid = Convert.ToInt32(maxMemberId);
            //    maxMemberId = (memberid + 1).ToString();

            //    List<string> list = new List<string>();
            //    string Write = "";
            //    for (int w = 0; w < maxMemberId.Length; w++)
            //    {
            //        list.Add(maxMemberId[w].ToString());
            //    }
            //    for (int s = 0; s < list.Count; s++)
            //    {
            //        if (list[s].ToString() == "4" || list[s].ToString() == "7")
            //        {
            //            list[s] = (Convert.ToInt32(list[s]) + 1).ToString();
            //        }
            //        Write += list[s];
            //    }
            //    maxMemberId = Write.PadLeft(8, '0');
            //    this.txtMenberId.Text = "8881" + areaMode.AreaNumber + maxMemberId;



            //    if (this.cbxArea.Text.Trim() != "" && this.cbxArea.Text.Length > 0)
            //    {
            //        this.lbAreaFK.Visible = false;
            //    }
            //}
            //else
            //{
            //    string memberID = this.txtMenberId.Text.Substring(8, this.txtMenberId.Text.Length - 8);
            //    Areas area = new Areas();
            //    ZG_member.Model.Areas areaMode = new ZG_member.Model.Areas();
            //    areaMode = area.getModelToString(this.cbxArea.Text);
            //    this.txtMenberId.Text = "8881" + areaMode.AreaNumber + memberID;
            //}

        }

        private void txtTel_TextChanged(object sender, EventArgs e)
        {
            if (this.txtTel.Text.Trim() != "" && this.txtTel.Text.Length > 0)
            {
                this.lbTelFK.Visible = false;
            }
        }

        private void cbxsex_TextChanged(object sender, EventArgs e)
        {
            if (this.cbxsex.Text.Trim() != "" && this.cbxsex.Text.Length > 0)
            {
                this.lbGenderFK.Visible = false;
            }
        }

        private void txtEmail_TextChanged(object sender, EventArgs e)
        {

        }

        private void txtMenberName_TextChanged(object sender, EventArgs e)
        {
            if (this.txtMenberName.Text.Trim() != "" && this.txtMenberName.Text.Length > 0)
            {
                this.lbNameFK.Visible = false;
            }
        }

        private void txtIDNumber_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!(((e.KeyChar >= '0') && (e.KeyChar <= '9')) || e.KeyChar <= 31))
            {
                //if (e.KeyChar == '.')
                //{
                //    if (((TextBox)sender).Text.Trim().IndexOf('.') > -1)
                //        e.Handled = true;
                //}
                //else
                e.Handled = true;
            }
            else
            {
                if (e.KeyChar <= 31)
                {
                    e.Handled = false;
                }
                else if (((TextBox)sender).Text.Trim().IndexOf('.') > -1)
                {
                    if (((TextBox)sender).Text.Trim().Substring(((TextBox)sender).Text.Trim().IndexOf('.') + 1).Length >= 4)
                        e.Handled = true;
                }
            }
        }

        private void txtMenberId_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!(((e.KeyChar >= '0') && (e.KeyChar <= '9')) || e.KeyChar <= 31))
            {
                //if (e.KeyChar == '.')
                //{
                //    if (((TextBox)sender).Text.Trim().IndexOf('.') > -1)
                //        e.Handled = true;
                //}
                //else
                e.Handled = true;
            }
            else
            {
                if (e.KeyChar <= 31)
                {
                    e.Handled = false;
                }
                else if (((TextBox)sender).Text.Trim().IndexOf('.') > -1)
                {
                    if (((TextBox)sender).Text.Trim().Substring(((TextBox)sender).Text.Trim().IndexOf('.') + 1).Length >= 4)
                        e.Handled = true;
                }
            }
        }

        private void label29_Click(object sender, EventArgs e)
        {

        }

        private void label8_Click(object sender, EventArgs e)
        {

        }

        private void Semester_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!(((e.KeyChar >= '0') && (e.KeyChar <= '9')) || e.KeyChar <= 31))
            {
                if (e.KeyChar == '.')
                {
                    if (((TextBox)sender).Text.Trim().IndexOf('.') > -1)
                        e.Handled = true;
                    else
                        e.Handled = true;
                }
                else
                    e.Handled = true;
            }
            else
            {
                if (e.KeyChar <= 31)
                {
                    e.Handled = false;
                }
                else if (((TextBox)sender).Text.Trim().IndexOf('.') > -1)
                {
                    if (((TextBox)sender).Text.Trim().Substring(((TextBox)sender).Text.Trim().IndexOf('.') + 1).Length >= 4)
                        e.Handled = true;
                }
            }
        }

        private void txtOpenTeacher_TextChanged(object sender, EventArgs e)
        {
            if (this.txtOpenTeacher.Text.Trim() != "" && this.txtOpenTeacher.Text.Length > 0)
            {
                this.lbOpenTeacherFK.Visible = false;
            }
        }

        private void txtpassword_TextChanged(object sender, EventArgs e)
        {
            if (this.txtpassword.Text.Trim() != "" && this.txtpassword.Text.Length > 0)
            {
                this.lbPassFK.Visible = false;
            }

        }

        private void txtpassword1_TextChanged(object sender, EventArgs e)
        {

        }

        private void txtpassword_Leave(object sender, EventArgs e)
        {
            if (this.txtpassword.Text == this.txtpassword1.Text)
            {
                this.lbPassFK2.Visible = false;
            }
            else
            {
                this.lbPassFK2.Visible = true;
            }
        }

        private void txtpassword1_Leave(object sender, EventArgs e)
        {
            if (this.txtpassword.Text == this.txtpassword1.Text)
            {
                this.lbPassFK2.Visible = false;
            }
            else
            {
                this.lbPassFK2.Visible = true;
            }
        }

        private void button1_Click_1(object sender, EventArgs e)
        { 
            OpenFileDialog ofdPic = new OpenFileDialog();
            ofdPic.Filter = "JPG(*.JPG;*.JPEG);gif文件(*.GIF)|*.jpg;*.jpeg;*png;*.gif";
            ofdPic.FilterIndex = 1;
            ofdPic.FileName = "";
            if (ofdPic.ShowDialog() == DialogResult.OK)
            { 
                string name = ofdPic.SafeFileName;
                string ex = Path.GetExtension(name);
                string sPicPaht = ofdPic.FileName.ToString();
                picName = Guid.NewGuid().ToString() + ex;
                string replaceUrl = Application.StartupPath.Replace("bin\\Debug", "photo\\" + picName);
                File.Copy(sPicPaht, replaceUrl, true);
                getPhoto(sPicPaht);
                updatePic = true;
            }
        }













    }
}

